<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
	.tree-node {padding:0;}
	img {
		height:50px;
		width:50px;
	}
</style>
<script type="text/javascript">
	$(function() {
		$('#toolbar_articleTable').toolbar({buttons:[
           	/* {name:'add',iconCls:'icon-add',text:'添加文章'}, */
       		{name:'reload',iconCls:'icon-reload',text:'刷新'}
      	],handler:handler});
		$('#category_datagrid_toolbar').toolbar({buttons:[
           	{name:'save_category',iconCls:'icon-ok',text:'投稿'},
      	],handler:handler});
		
	    $('#article_datagrid').datagrid({
	    	url:'page',
    		pagination:true,
    		singleSelect:true,
    		pageSize:20,
    		rownumbers:false,
    		striped:true,
    		fit:true,
    		fitColumns:true,
    		toorbar:'#toolbar_articleTable',
    		columns:[[
    			{field:'id',title:'编号'},
    			{field:'articleTitle',title:'文章标题'},
        		{field:'userName',title:'作者'},
        		{field:'articleType',title:'类型',formatter:function(v,r,i){
        			var type ="";
        			if(r.articleType == "1"){type ="文章"}else if(r.articleType == "3"){type ="音频"}else if(r.articleType == "5"){type="视频"}else if(r.articleType == "7"){type="话题pk"}
        			return type;
        		}},
        		{field:'markPublish',title:'发布标记',formatter:function(v,r,i){
        			var publish='私密';
        			if(r.markPublish){
        				publish='公开';
        			}
        			return publish;
        		}},
        		{field:'countView',title:'浏览量'},
        		{field:'countPraise',title:'点赞量'},
        		{field:'countShare',title:'分享量'},
        		{field:'countCollect',title:'收藏量'},
        		{field:'markAudit',title:'审核标记',formatter:function(v,r,i){
        			var audit='未审核';
        			if(r.markAudit == '3'){
        				audit='审核未通过';
        			}else if(r.markAudit == '5'){
        				audit='审核通过';
        			}
        			return audit;
        		}},
        		{field:'categoryId',title:'投稿',formatter:function(v,r,i){
        			var category='未投稿';
        			if(r.categoryId > 0){
        				category='已投稿';
        			}
        			return category;
        		}},
        		{field:'enabled',title:'是否可用',formatter:function(v,r,i){
        			var enab = '否';
        			if(r.enabled){
        				enab = '是'
        			}
        			return enab;
        		}},
        		{field:'createdDt',title:'创建时间'},
        		{field:'-',title:'操作',align:'center',formatter:function(v,r,i){
        			var action = '<a href="#" onclick="toEdit('+r.id+');">编辑</a>&nbsp;&nbsp;';
        			if(r.enabled){
        				action = action+'<a href="#" onclick ="enabled('+r.id+');">禁用</a>';
        				if(r.categoryId < 1){
        					action = action+'&nbsp;&nbsp;<a href="#" onclick="addCategory('+i+');">去投稿</a>';
        				}
        			}else{
        				action = action+'<a href="#" onclick="disbled('+r.id+');">启用</a>';
        				
        			}
        			action = action+'&nbsp;&nbsp;<a href="#" onclick="detail('+r.id+');">查看</a>';
        			
					return action;
				}}
    		]],
    		view: detailview,
    	    detailFormatter: function(rowIndex, rowData){
    	        return '<table><tr>' +
    	                '<td rowspan=2 style="border:0,height:50px;">'+rowData.articleContent+'</td>' +
    	                '</tr></table>';
    	    }
		 });
		
		 //过滤条件参数
		function getItem(){
			var userName = $.trim($("#search_user").textbox("getValue"));
			var articleTitle = $.trim($("#search_articleTitle").textbox("getValue"));
			var articleType = $.trim($("#search_articleType").combobox("getValue"));
			var enabled = $.trim($("#search_enabled").combobox("getValue"));
			var searchItem = {};
			if(userName.length>0){
				searchItem.userName=userName;
			}
			if(articleTitle.length>0){
				searchItem.articleTitle=articleTitle;
			}
			if(articleType.length>0){
				searchItem.articleType=articleType;
			}
			if(enabled.length>0){
				searchItem.enabled=enabled;
			}
			return searchItem;
		}
		function handler() {
			switch(this.name) {
				//case 'add': toAdd();break;
				case 'add': openType();break;
				
				case 'save_category': saveCategory();break;
			}
		}
		function openType(){
			$('#dialog_articleType').dialog('open');
		}
		function toAdd(type) {
			show({code:'tag_info_add',title:'添加文章信息',iconCls:'icon-add',uri:'add?type='+type,width:800,height:800,
				options : {
					success : function(data) { 
						$('#article_datagrid').datagrid('reload'); 
					}
				}
			});
		}

	
	$("#a_searchTag").click(function(){
		reloadDate();
	});
	$("#a_clearn").click(function(){
		resetData();
	});
		
		function reloadDate(){
			var item = getItem();
			$('#article_datagrid').datagrid({ queryParams: item});   //点击搜索
		}
		function resetData(){
			$("#search_user").textbox("setValue","");
			$("#search_articleTitle").textbox("setValue","");
			$("#search_articleType").combobox("setValue","");
			$("#search_enabled").combobox("setValue","");
			reloadDate();
		}
	});
	//编辑
	function toEdit(item) {
		show({code:'tag_info_edit',title:'编辑文章信息',iconCls:'icon-edit',uri:'edit?id='+item,width:900,height:900,
			options : {
				success : function(data) { 
					$('#article_datagrid').datagrid('reload'); 
				}
			}
		});
	}
	//查看详细
	function detail(item){
		show({code:'tag_info_detail',title:'文章信息',iconCls:'icon-edit',uri:'detail?id='+item,width:900,height:900,
			options : {
				success : function(data) { 
					$('#article_datagrid').datagrid('reload'); 
				}
			}
		});
	}
	function disbled(id){
		var parms = {};
		parms.id = id;
		parms.enabled = true;
		$.post('updateEnabled',parms,function(r){
			if(r.code>0){
				$('#article_datagrid').datagrid('reload'); 
			};
		},'json');
	}
	//更新可用标记
	function enabled(id){
		var parms = {};
		parms.id = id;
		parms.enabled = false;
		$.post('updateEnabled',parms,function(r){
			if(r.code>0){
				$('#article_datagrid').datagrid('reload'); 
			};
		},'json');
	}
	
	//去投稿
	function addCategory(index){
		$('#article_datagrid').datagrid('selectRow',index);
		var article = $('#article_datagrid').datagrid('getSelected');
		if(article != null && article != ""){
			$('#category_grid').datagrid("load");
			$('#dialog_category').dialog('open');
		}
	}
	function saveCategory(){
		var article = $('#article_datagrid').datagrid('getSelected');
		var categorys = $('#category_datagrid').datagrid("getSelected");
		if(article =='' || article == null){
			alert("没有选中文章");
			return;
		}
		if(categorys == null || categorys ==''){
			alert("没有选中栏目");
			return;
		}
		var params = {};
		params.articleId = article.id;
		params.categoryId = categorys.id;

		$.post('${ctx}/article/info/contributeTo',params,function(r){
			if(r.code<0)return top.$alert(r.msg);
			$('#dialog_category').dialog('close');
			$('#article_datagrid').datagrid("load");
			top.$ok('投稿成功！');
		},'json');
		
		
		function createKind(){
			
		}
		
	}
	function addTypeText(){
		$('#dialog_articleType').dialog('close');
		toAdd(1);
		//alert("图文");
	}
	function addTypeSound(){
		$('#dialog_articleType').dialog('close');
		toAdd(3);
		//alert("音频");
	}
	function addTypeMovie(){
		$('#dialog_articleType').dialog('close');
		toAdd(5);
		//alert("电影");
	}
	function addTypePk(){
		//alert("pk");
		$('#dialog_articleType').dialog('close');
		toAdd(7);
	}
	function toAdd(type) {
		show({code:'tag_info_add',title:'添加文章信息',iconCls:'icon-add',uri:'add?type='+type,width:800,height:830,
			options : {
				success : function(data) { 
					$('#article_datagrid').datagrid('reload'); 
				}
			}
		});
	}
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false">
			<fieldset>
    		<legend>过滤条件</legend>
    		<table style="width:100%">
    			<tr>
    				<td>文章标题:<input id="search_articleTitle" class="easyui-textbox" data-options="prompt:'请输入文章名称'" ></td>
    				<td>文章作者:<input id="search_user" class="easyui-textbox" data-options="prompt:'请输入作者'" ></td>
    				<td>
    					文章类型:
    					<select id="search_articleType" class="easyui-combobox" data-options="width:60,panelHeight:100">
    						<option></option>
    						<option value="1">文章</option>
    						<option value="3">音频</option>
    						<option value="5">视频</option>
    						<option value="7">话题pk</option>
    					</select>
    				</td>
    				<td>
    					是否可用:
    					<select id="search_enabled" class="easyui-combobox" name="enabled" data-options="width:50,panelHeight:60">
    						<option> </option>
    						<option value="1">是</option>
    						<option value="0">否</option>
    					</select>
    				</td>
    				<td><a id="a_searchTag" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
    				<td>
    					<a id="a_clearn" class="easyui-linkbutton" iconCls="icon-undo">清除</a>
    				</td>
    			</tr>
    		</table>
  		</fieldset>
		</div>
  		<div data-options="region:'center',border:false" style="padding-bottom: 33px">
            <div id="toolbar_articleTable" class="toolbar"></div>
  			<table id="article_datagrid"></table>
		</div>
		
		<div id="dialog_category" class="easyui-dialog" data-options="closed:true," title="投稿到" style="width:600px;height:300px;padding:10px">
			<div id="category_datagrid_toolbar" class="toolbar" ></div>
			<table id="category_datagrid" class="easyui-datagrid" data-options="rownumbers:true,singleSelect:true,pagination:true,url:'/category/info/page',method:'post'">
				<thead>
					<tr>
						<th data-options="field:'ck',checkbox:true"></th>
						<th data-options="field:'id',width:80">编号</th>
						<th data-options="field:'name',width:100">栏目名称</th>
						<th data-options="field:'note',width:80,align:'right'">备注</th>
					</tr>
				</thead>
			</table>
		</div>
		<div id="dialog_articleType" class="easyui-dialog" data-options="closed:true," title="选择添加文章的类型" style="width:280px;height:180px;padding:10px">
			<table>
				<tr>
					<td><a href="#" id="type_article" onclick="addTypeText();" class="easyui-linkbutton c1" style="width:120px;height: 50px;">图文</a></td>
					<td><a href="#" id="type_sound" onclick="addTypeSound();" class="easyui-linkbutton c2" style="width:120px;height: 50px;">音频</a></td>
				</tr>
				<tr>
					<td><a href="#" id="type_pk" onclick="addTypePk();" class="easyui-linkbutton c3" style="width:120px;height: 50px;">话题pk</a></td>
					<td><a href="#" id="type_movie" onclick="addTypeMovie();" class="easyui-linkbutton c4" style="width:120px;height: 50px;">视频</a></td>
				</tr>
			</table>
		</div>
	</div>
</body>
</html>